import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

import cn from '@/i18n/lang/zh.js'
import en from '@/i18n/lang/en.js'

const lang={
    'cn':cn,
    'en':en
}
let getCookie = (name) => {
    let arr = null
    let reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
    if (document.cookie.match(reg)) {
      arr = document.cookie.match(reg)
      return unescape(arr[2])
    } else {
      return null
    }
}
// 创建多语言对象
const nativeLan= navigator.language || navigator.userLanguage;
const lowerLan = nativeLan.toLowerCase();
let languange='';
if(lowerLan.indexOf('cn')>-1){
	languange='cn'
}else if(lowerLan.indexOf('en')>-1){
	languange='en'
}else {
	languange='en'
}

if(getCookie('lan')){
    languange = getCookie('lan')
}
const i18n = new VueI18n({
    locale: languange, // 语言标识
    messages:lang
})

export default i18n